<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>意达设计</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/member.css"/>

</head>
<body class="body">

<!-- header -->
<div class="pageheader"><a href="javascript:void(0);" onclick="api.closeWin();" class="return"></a><span>申请成为会员</span></div>

<!-- contact -->
<div class="wrop">
	<div class="memlist"><span>联系人姓名</span><input type="text" name="nickname" placeholder="请填写姓名"></div>
	<div class="memlist"><span>联系人电话</span><input type="text" name="phone" placeholder="请填写电话号码"></div>
	<div class="memlist"><span>联系人邮箱</span><input type="text" name="email" placeholder="请填写邮箱"></div>
	<div class="memlist"><span>公司名称</span><input type="text" name="cpyname" placeholder="请填写公司名称"></div>
	<div class="memlist"><span>所在城市</span><input type="text" name="city" placeholder="请填写公司所在城市"></div>
	<div class="memlist"><span>公司地址</span><input type="text" name="addr" placeholder="请填写公司所在具体地址"></div>
	<div class="memlist"><span>公司邮编</span><input type="text" name="yb" placeholder="请填写公司所在邮编"></div>
	<div class="memlist"><span>PARTITA IVA</span><input type="text" name="shopno" placeholder="请如实填写营业执照号码"></div>
	<div class="memlist memlistToo"><span>CODICE FISCALE</span><input type="text" name="greenno" placeholder="请如实填写绿卡号码"></div>
	<div class="tblist">
		<span>证件类型</span>
		<div class="sfid">
			<label class="sfid_on"><em>身份证</em><input type="radio" name="sfzID" checked="checked"></label>
			<label><em>居留证</em><input type="radio" name="sfzID"></label>
		</div>
	</div>
	<div class="szlie">
		<div class="sz_li sz_liOn">
			<p>有效身份证</p>
			<div class="szbox"><img src="../image/page/img-001.jpg" onclick="showAction('n1')" id='n1'></div>
			<div class="szbox"><img src="../image/page/img-002.jpg" onclick="showAction('n2')" id='n2'></div>
		</div>
		<div class="sz_li">
			<p>有效居留证</p>
			<div class="szbox"><img src="../image/page/img-003.jpg" onclick="showAction('n3')" id='n3'></div>
			<div class="szbox"><img src="../image/page/img-004.jpg" onclick="showAction('n4')" id='n4'></div>
		</div>
	</div>
	<input type="hidden" name="zm" placeholder="请填写姓名">
	<input type="hidden" name="fm" placeholder="请填写姓名">
	<div class="subBtn"><button onclick="tijiao()">确认提交</button></div>
	
</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/adaptive.js"></script>
<script type="text/javascript" src="../script/tabs.js"></script>
<script type="text/javascript">
    window['adaptive'].desinWidth = 750;
    window['adaptive'].baseFont = 28;
    window['adaptive'].maxWidth = 750;
    window['adaptive'].init();

    apiready = function () {
        $api.fixStatusBar($api.dom('.header'));
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            api.closeWidget();
        });
        
        //api.showProgress();

    }
        function tijiao(){
        	var nickname=$("input[name=nickname]").val();
            var phone=$("input[name=phone]").val();
            var email=$("input[name=email]").val();
            var cpyname=$("input[name=cpyname]").val();
            var city=$("input[name=city]").val();
            var addr=$("input[name=addr]").val();
            var yb=$("input[name=yb]").val();
            var shopno=$("input[name=shopno]").val();
            var greenno=$("input[name=greenno]").val();
            var zm=$("input[name=zm]").val();
            var fm=$("input[name=fm]").val();
           /* var zm=1;
            var fm=2;*/
            
            if(nickname==''){
                api.alert({msg:"请输入姓名！"});return;
            }else if(phone==''){
                api.alert({msg:"请输入手机号！"});return;
            }else if( !/^1[34578]\d{9}$/.test(phone)){
                api.alert({msg:"手机号格式错误！"});return;
            }else if(email==''){
                api.alert({msg:"请输入邮箱！"});return;
            }else if( !/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/.test(email)){
                api.alert({msg:"邮箱格式错误！"});return;
            }else if(cpyname==''){
                api.alert({msg:"请输入公司名称！"});return;
            }else if(city==''){
                api.alert({msg:"请输入城市！"});return;
            }else if(addr==''){
                api.alert({msg:"请输入地址！"});return;
            }else if(yb==''){
                api.alert({msg:"请输入邮编！"});return;
            }else if(shopno==''){
                api.alert({msg:"请输入执照号码！"});return;
            }else if(greenno==''){
                api.alert({msg:"请输入绿卡号码！"});return;
            }else if(zm==''){
                api.alert({msg:"请选择证件正面图片！"});return;
            }else if(fm==''){
                api.alert({msg:"请选择证件反面图片！"});return;
            }

var p={nickname:nickname,phone:phone,email:email,cpyname:cpyname,city:city,addr:addr,yb:yb,shopno:shopno,greenno:greenno,zm:zm,fm:fm};
            api.ajax({
                url: webSiteUrl+'/app/public/reg',
                method: 'post',
                data: {
                    
                    values: p
                }
            }, function(ret, err) {
                
                
                if(ret.code==200){
                    
                   alert(ret.msg);
                   api.openWin({
                        name: 'shopName',
                        url: './slide.html',
                        pageParam: {
                            
                        }
                    });

                   
                }else{alert(ret.msg)}
            });

        }

function showAction(id) {
    api.actionSheet({
         title: '上传图片',
         cancelTitle: '取消',
         buttons: ['拍照', '从手机相册选择']
    }, function(ret, err) {
         if (ret) {
             getPicture(ret.buttonIndex,id);
         }
    });
 }
 function getPicture(sourceType,id) {
        if (sourceType == 1) { // 拍照
            //获取一张图片
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'png',
                mediaValue: 'pic',
                allowEdit: false,
                quality: 90,
                saveToPhotoAlbum: true
            }, function(ret, err) {
                if(ret.data==''){return;}
                
                if (ret) {

                    var imgSrc = ret.data;
                    if (imgSrc != "") {
                        
                        //$api.attr(ele, 'src', imgSrc);
                    }
                    if (ret.hasOwnProperty("list")) {
                        
                        //var localAvaterPath = ret.data;
                        //$api.attr(ele, 'src', ret.list[0].path);
                        api.showProgress({
                            title: '正在上传...',
                            modal: true
                        });
                    }
                    var ele = $api.dom('#'+id);
                    api.ajax({
                        url: webSiteUrl+'/app/public/uploads',
                        method: 'post',
                        data: {
                            files: {
                                'file': ret.data,
                            }
                        }
                    }, function(ret, err) {
                        if (ret) {
                            if (ret.code == 200) {
                                //$api.attr(ele, 'src', ret.data);
                                $api.attr(ele, 'src', webSiteUrl+ret.pic);
                                api.hideProgress();
                                //alert(JSON.stringify(ret));
                                if(id=='n1' || id=='n3'){
                                    $("input[name=zm]").val(ret.id);
                                    
                                }else{
                                    $("input[name=fm]").val(ret.id);
                                }

                            } else {
                                api.hideProgress();
                                api.toast({
                                    msg: ret.msg,
                                    location: 'middle'
                                });
                            }
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: err.msg,
                                location: 'middle'
                            });
                        }
                    });




                }
            });
        } else if (sourceType == 2) { // 从相机中选择
            //UIMediaScanner 是一个多媒体扫描器，可扫描系统的图片、视频等多媒体资源
            var obj = api.require('UIMediaScanner');
            obj.open({
                //返回的资源种类,picture（图片）,video（视频）,all（图片和视频）
                type: 'picture',
                //（可选项）图片显示的列数，须大于1
                column: 4,
                max: 1,
                //（可选项）图片排序方式,asc（旧->新）,desc（新->旧）
                sort: {
                    key: 'time',
                    order: 'desc'
                },
                //（可选项）模块各部分的文字内容
                texts: {
                    stateText: '已选择*项',
                    cancelText: '取消',
                    finishText: '完成'
                },
                styles: {
                    bg: '#fff',
                    mark: {
                        icon: '',
                        position: 'bottom_right',
                        size: 20
                    },
                    nav: {
                        bg: '#eee',
                        stateColor: '#000',
                        stateSize: 18,
                        cancleBg: 'rgba(0,0,0,0)',
                        cancelColor: '#000',
                        cancelSize: 18,
                        finishBg: 'rgba(0,0,0,0)',
                        finishColor: '#000',
                        finishSize: 18
                    }
                }
            }, function(ret) {
                if(ret.eventType=='cancel'){return;}
                if (ret) {

                    
                    if (ret.hasOwnProperty("list")) {
                        
                        //var localAvaterPath = ret.list[0].path;
                        //$api.attr(ele, 'src', ret.list[0].path);
                        api.showProgress({
                            title: '正在上传...',
                            modal: true
                        });
                    }
                    var ele = $api.dom('#'+id);
                    api.ajax({
                        url: webSiteUrl+'/app/public/uploads',
                        method: 'post',
                        data: {
                            files: {
                                'file': ret.list[0].path,
                            }
                        }
                    }, function(ret, err) {
                        if (ret) {
                            if (ret.code == 200) {
                                
                                $api.attr(ele, 'src', webSiteUrl+ret.pic);
                                api.hideProgress();
                                //alert(JSON.stringify(ret));
                                 if(id=='n1' || id=='n3'){
                                    $("input[name=zm]").val(ret.id);
                                    
                                }else{
                                    $("input[name=fm]").val(ret.id);
                                }

                            } else {
                                api.hideProgress();
                                api.toast({
                                    msg: ret.msg,
                                    location: 'middle'
                                });
                            }
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: err.msg,
                                location: 'middle'
                            });
                        }
                    });





                }
            });
        }
    }

</script>

</html>
